﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using TalentPools.Model;

namespace TalentPools.DAL
{
   public class Person_BaseMeansService
    {
       /// <summary>
       /// 查询是否完善资料
       /// </summary>
       /// <param name="username"></param>
       /// <returns></returns>
       public int GetBeanMeanCount(string username)
       {
           string sql = "select count(1) from Person_BaseMeans where username=@username";
           SqlParameter para = new SqlParameter("@username", username);
           return (int)DBHelper.ExecuteScalar(CommandType.Text, sql, para);
       }
       public Person_BaseMeans GetBaseMean(string username)
       {
           string sql = "select * from Person_BaseMeans where username=@username";
           SqlParameter para = new SqlParameter("@username", username);
           using (SqlDataReader dr=DBHelper.ExecuteGetReader(CommandType.Text,sql,para))
           {
               while (dr.Read())
               {
                   Person_BaseMeans basemean = new Person_BaseMeans();
                   basemean.Id = Convert.ToInt32(dr["Id"]);
                   basemean.username = dr["username"].ToString();
                   basemean.name = dr["name"].ToString();
                   basemean.sex = dr["sex"].ToString();
                   basemean.birthday = Convert.ToDateTime(dr["birthday"]);
                   basemean.marriage = dr["marriage"].ToString();
                   basemean.card = dr["card"].ToString();
                   basemean.politicsStatus = dr["politicsStatus"].ToString();
                   basemean.HKPlace = dr["HKPlace"].ToString();
                   basemean.city = dr["city"].ToString();
                   basemean.currentAddress = dr["currentAddress"].ToString();
                   basemean.zipCode = dr["zipCode"].ToString();
                   basemean.cellphone = dr["cellphone"].ToString();
                   basemean.phoneCode = dr["phoneCode"].ToString();
                   basemean.email = dr["email"].ToString();
                   basemean.homePage = dr["homePage"].ToString();
                   return basemean;
               }
               return null;
           }
       }
       public bool InsertBaseMean(Person_BaseMeans basemean)
       {
           string sql = "insert into Person_BaseMeans(username,name,sex,birthday,marriage,card,politicsStatus,HKPlace,city,currentAddress,zipCode,cellphone,phoneCode,email,homePage)values(@username,@name,@sex,@birthday,@marriage,@card,@politicsStatus,@HKPlace,@city,@currentAddress,@zipCode,@cellphone,@phoneCode,@email,@homePage)";
           SqlParameter[] paras = new SqlParameter[] { 
           new SqlParameter("@username",basemean.username),
           new SqlParameter("@name",basemean.name),
           new SqlParameter("@sex",basemean.sex),
           new SqlParameter("@birthday",basemean.birthday),
           new SqlParameter("@marriage",basemean.marriage),
           new SqlParameter("@card",basemean.card),
           new SqlParameter("@politicsStatus",basemean.politicsStatus),
           new SqlParameter("@HKPlace",basemean.HKPlace),
           new SqlParameter("@city",basemean.city),
           new SqlParameter("@currentAddress",basemean.currentAddress),
           new SqlParameter("@zipCode",basemean.zipCode),
           new SqlParameter("@cellphone",basemean.cellphone),
           new SqlParameter("@phoneCode",basemean.phoneCode),
           new SqlParameter("@email",basemean.email),
           new SqlParameter("@homePage",basemean.homePage)
           };
           return DBHelper.ExecuteNonQuery(CommandType.Text, sql, paras) > 0;
       }
       public bool UpdateBaseMean(Person_BaseMeans basemean)
       {
           string sql = "update Person_BaseMeans set name=@name,sex=@sex,birthday=@birthday,marriage=@marriage,card=@card,politicsStatus=@politicsStatus,HKPlace=@HKPlace,city=@city,currentAddress=@currentAddress,zipCode=@zipCode,cellphone=@cellphone,phoneCode=@phoneCode,email=@email,homePage=@homePage where username=@username";
           SqlParameter[] paras = new SqlParameter[] { 
           new SqlParameter("@username",basemean.username),
           new SqlParameter("@name",basemean.name),
           new SqlParameter("@sex",basemean.sex),
           new SqlParameter("@birthday",basemean.birthday),
           new SqlParameter("@marriage",basemean.marriage),
           new SqlParameter("@card",basemean.card),
           new SqlParameter("@politicsStatus",basemean.politicsStatus),
           new SqlParameter("@HKPlace",basemean.HKPlace),
           new SqlParameter("@city",basemean.city),
           new SqlParameter("@currentAddress",basemean.currentAddress),
           new SqlParameter("@zipCode",basemean.zipCode),
           new SqlParameter("@cellphone",basemean.cellphone),
           new SqlParameter("@phoneCode",basemean.phoneCode),
           new SqlParameter("@email",basemean.email),
           new SqlParameter("@homePage",basemean.homePage)
           };
           return DBHelper.ExecuteNonQuery(CommandType.Text, sql, paras) > 0;
       }
    }
}
